package cn.iocoder.yudao.module.system.util.a_gaojian;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * @author zyk
 */
public class DateTimeUtils {

    public final static String FORMAT = "yyyy-MM-dd HH:mm:ss";

    public final static String FORMAT_DATE = "yyyy-MM-dd";

    public static String getDate(){
        return getDate(FORMAT);
    }

    public static String buildTimestamp(Timestamp timestamp){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATE);
        return simpleDateFormat.format(timestamp);
    }

    public static String buildDate(Date date){
        return buildDate(date,FORMAT);
    }

    public static String buildDate(Timestamp time){
        return buildDate(time,FORMAT);
    }
    public static String buildDate(Date date,String format){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(date);
    }

    public static String buildDate(Timestamp timestamp,String format){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(timestamp);
    }

    public static String getDate(String format){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format));
    }

    public static String getFileName(){
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 5; i++) {
            sb.append(random.nextInt(10));
        }
        Long time = new java.util.Date().getTime();
        return String.valueOf(time) + sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(getFileName());
    }
}
